package com.zx.wangyixinwen.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.Toast;

import com.android.volley.toolbox.NetworkImageView;
import com.zx.wangyixinwen.MyRequestQueue;
import com.zx.wangyixinwen.R;

import java.util.List;

/**
 * Created by dllo on 16/1/12.
 */
public class HeadlinesViewPagerAdapter extends PagerAdapter {

    private Context context;
    private List<View> views;

    public HeadlinesViewPagerAdapter(List<View> views, Context context) {
        this.views = views;
        this.context = context;
    }

    @Override
    public int getCount() {
        if (views.size() > 1) {
            return Integer.MAX_VALUE;
        } else
            return views.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        int index = position % views.size();
        if (index < 0) {
            index = views.size() + index;
        }
        View view = views.get(index);
        NetworkImageView imageView = (NetworkImageView) view.findViewById(R.id.item_iv_head);
        Log.e("kk", imageView.toString());
//        MyRequestQueue.setNetImage(imageView,);
        ViewParent vp = view.getParent();
        if (vp != null) {
            ViewGroup group = (ViewGroup) vp;
            group.removeView(view);
        }
        container.addView(view);
        return view;
    }
}
